package com.zyd.shiro.business.controller.pak;

import com.github.pagehelper.PageInfo;
import com.zyd.shiro.business.entity.InventoryLine;
import com.zyd.shiro.business.service.PakInventoryLineService;
import com.zyd.shiro.framework.object.BaseConditionVO;
import com.zyd.shiro.framework.object.PageResult;
import com.zyd.shiro.framework.object.ResponseVO;
import com.zyd.shiro.util.ResultUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.zyd.shiro.persistence.beans.PakInventoryLine;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import java.io.File;
import com.zyd.shiro.utils.FileUtils;
import com.zyd.shiro.utils.ExcelUtil;
import java.util.Date;


@RestController
@RequestMapping("/inventoryLine")
@Api(description = "资产盘点明细")
public class PakInventoryLineController {
    @Autowired
    private PakInventoryLineService inventoryLineService;

    @PostMapping
    @ApiOperation(value="添加", produces="application/json")
    public ResponseVO insert(InventoryLine inventoryLine) {
        inventoryLineService.insert(inventoryLine);
        return ResultUtil.success("添加成功！",null);
    }

    @PutMapping
    @ApiOperation(value="修改", produces="application/json")
    public ResponseVO update(InventoryLine inventoryLine) {
        inventoryLineService.updateSelective(inventoryLine);
        return ResultUtil.success("修改成功！",null);
    }

    @DeleteMapping(value = "/{id}")
    @ApiOperation(value="主键删除", produces="application/json")
    public ResponseVO delete(@PathVariable(name="id") Long id){
        inventoryLineService.removeByPrimaryKey(id);
        return ResultUtil.success("删除成功！",null);
    }

    @GetMapping
    @ApiOperation(value="分页查询", produces="application/json")
    public PageResult page(BaseConditionVO vo) {
        PageInfo<InventoryLine> pageInfo = inventoryLineService.findPageBreakByCondition(vo);
        return ResultUtil.tablePage(pageInfo);
    }

    @GetMapping(value = "/all")
    @ApiOperation(value="查询所有", produces="application/json")
    public ResponseVO list() {
        List<InventoryLine> inventoryLines = inventoryLineService.listAll();
        return ResultUtil.success("查询成功！",inventoryLines);
    }

 /*   @PostMapping(value = "/import")
    @ApiOperation(value="批量导入", produces="application/json")
    public ResponseVO folderImport(MultipartFile file) throws Exception {
        String fileName = file.getOriginalFilename();
        String suffix = fileName.substring(fileName.indexOf("."), fileName.length());
        if (suffix.equals(".xlsx") || suffix.equals(".xls")) {
            File newFile = new File(FileUtils.createFilePath(fileName));
            file.transferTo(newFile);
            ExcelUtil<PakInventoryLine> excelUtil = new ExcelUtil<>();
            List<PakInventoryLine> acfForms = excelUtil.importExcel("Sheet1", newFile, PakInventoryLine.class);
            for (PakInventoryLine a : acfForms) {
                a.setCreateTime(new Date());
                a.setUpdateTime(new Date());
                inventoryLineService.increase(a);
            }
            return ResultUtil.success("修改成功！");
        }
        return ResultUtil.error("请输入excel文件!");
    }*/


}